import java.util.Stack;

import javax.swing.ImageIcon;

@SuppressWarnings("serial")
public class Deck extends Stack<Card> {
	
	public Deck() {
		
		ClassLoader loader = this.getClass().getClassLoader();
		
		for (Suit suit: Suit.values()) {
			for (Face face : Face.values()) {
				String cardImagePath = "resources/cards/" + face.toString() + suit.toString().charAt(0) + ".gif";
				//this.add(new Card(face, suit, new ImageIcon(cardImagePath)));
				this.add(new Card(face, suit, new ImageIcon(loader.getResource(cardImagePath))));
			}
		}
	}
	
    /*
     * Uses the Fisher_Yates shuffle algorithm
     */
	public void shuffle() {
		
	    Card tempCard;
	    int tempIndexInDeck;
	    for (int i = this.size() - 1; i >= 0; i--){ 
	      tempIndexInDeck = ((int) (i * Math.random())); 
	      if (tempIndexInDeck != i){
	        tempCard = this.get(i);
	        this.set(i, this.get(tempIndexInDeck));
	        this.set(tempIndexInDeck, tempCard);
	      }
	    }
	  }
}
